#ifndef MYMUDUO_NET_TCPSERVER_H
#define MYMUDUO_NET_TCPSERVER_H

#include <map>
#include <boost/noncopyable.hpp>

#include <muduo/net/InetAddress.h>
#include <muduo/net/EventLoop.h>

using namespace muduo;
using namespace muduo::net;

namespace mymuduo
{
class TcpServer: boost::noncopyable
{
public:
	TcpServer(EventLoop* loop, const InetAddress& listenaddr);
	~TcpServer();

	void start();

	void setConnectionCallback(const ConnectionCallback& cb)
	{ connectionCallback_ = cb; }

	void setMessageCallback(const MessageCallback& cb)
	{ messageCallback_ = cb; }
private:
	void newConnection(int fd, const InetAddress& peerAddr);

	typedef std::map<std::string, TcpConnectionPtr> ConnectionMap;

	EventLoop* loop_;
	const std::string name_;
	boost::scoped_ptr<Acceptor> acceptor_;
	ConnectionCallback connectionCallback_;
	MessageCallback    messageCallback_;
	bool start_;
	int nextConnId_;
	ConnectionMap connections_;
}
}
#endif

